# -*- coding: utf-8 -*-

import urllib2
import json
import hashlib
import random
import string
import time

headers = {"User-Agent":"Buyer/5.6.0 (com.ymatou.Shopping; build:5.6.0.1; iOS 10.0.0) Alamofire/5.6.0",
           "sign":"080f37571f6c65d9b8f0d881f120fadb1234ddgsfgda",
           "timestamp":int(round(time.time() * 1000))}
homeprodlist = []
for index in range(10):
    homeprodurl = 'https://app.ymatou.com/api/guess/homeprod?pageindex='+ str(index) + '&pagetype=app_home_page'

    homeprod_request = urllib2.Request(homeprodurl, headers = headers);
    homeprod_response = urllib2.urlopen(homeprod_request).read()
    homeprod_hjson = json.loads(homeprod_response)


    for i in range(len(homeprod_hjson["prodList"])):

        if homeprod_hjson["prodList"][i]["type"] != 1:
            continue;

        productId = homeprod_hjson["prodList"][i]["id"];

        homeprodlist.append(str(productId) + '\n');

with open('../homeprodid.dat', 'w') as f:
    f.write('productid\n')
    f.writelines(homeprodlist)